<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://sf3-cn.feishucdn.com/obj/static/lark/passport/qrcode/LarkSSOSDKWebQRCode-1.0.1.js"></script>
</head>
<body>
  <h1>飞书扫码登录--第三方授权登录</h1>
  <hr/>

  <div id="login_container"></div>

  <script>
    var backUrl = "http://c26a-2409-8954-3414-7b19-7d69-b84e-7ffd-fea7.ngrok.io"
    var config={
      client_id: "cli_a2dc74533c78500d",
      redirect_uri: decodeURIComponent(backUrl)
    }
    var url = `https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=${config.client_id}&redirect_uri=${config.redirect_uri}&response_type=code&state=state123456`;

    // 利用前端网页跳转
    // window.location.href = url;

    var QRLoginObj = QRLogin({
                id:"login_container",
                goto: url,
                // goto: "https://passport.feishu.cn/suite/passport/oauth/authorize?client_id=cli_a03f23493d39d00e&redirect_uri=https%3A%2F%2Fwww.baidu.com&response_type=code&state=STATE",
                width: "300",
                height: "300",
            });     
            var handleMessage = function (event) {
              console.error('event',event);    
                var origin = event.origin;    
                // 使用 matchOrigin 方法来判断 message 是否来自飞书页面
                if( QRLoginObj.matchOrigin(origin) ) {           
                    var loginTmpCode = event.data; 
                    // 在授权页面地址上拼接上参数 tmp_code，并跳转
                    //window.location.href = `${goto}&tmp_code=${loginTmpCode}`;
                    console.log(loginTmpCode)
                }
            };
            if (typeof window.addEventListener != 'undefined') {   
                window.addEventListener('message', handleMessage, false);} 
            else if (typeof window.attachEvent != 'undefined') { 
                window.attachEvent('onmessage', handleMessage);
            }
            // 原文链接：https://blog.csdn.net/xutongbao/article/details/123278795
  </script>

</body>
</html>